home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2807 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  48 lines

  1. Newsgroups: comp.lang.c
  2. Path: bunyip.cc.uq.oz.au!un!news
  3. From: al012@svtstu.seqeb.gov.au (Anthony Lee)
  4. Subject: Why isn't return address in the stack protected?
  5. X-Nntp-Posting-Host: 147.209.150.100
  6. Message-ID: <DLo4xF.MH@un.seqeb.gov.au>
  7. Sender: news@un.seqeb.gov.au (USENET News System)
  8. Organization: Your Organization
  9. X-Newsreader: WinVN 0.93.14
  10. Mime-Version: 1.0
  11. Date: Wed, 24 Jan 1996 04:39:14 GMT
  12.  
  13. void log_event(void)
  14. {
  15.      char message[256]; 
  16.     int i;
  17.  
  18.     sprintf(message,
  19.         "     Event, node: %d, seq:%08.8x, type:%02.2d, 
  20. length:%03.3d, data: ",
  21.         nodeid, me.seqno, me.type, me.length);
  22.  
  23.     for ( i = 0; i < me.length; i++)
  24.            sprintf(&message[strlen(message)],"%02.2x 
  25. ",me.data.array[i] & 0xff);
  26.     printf("%s\n", message);
  27.  
  28. }
  29.  
  30. In the above code if the me.length is such that the resultant
  31. string is longer than the size of message (> 256 bytes).  Then
  32. my C program would happily sprintf into message.  The problem is
  33. that it starts writing all over the stack causing the program
  34. to fall over.  My question is why can't the run time environment
  35. protect the stack from such access and flag an error?
  36. -- 
  37. Anthony Lee        These are my opinions and not SEQEB.
  38. SEQEB                                            
  39. 150 Charlotte Street                   ..--  __o 
  40. Brisbane                          ....--   _ \<,_               
  41. Qld 4000                         ____     (_)/ (_)                       
  42.   
  43. Australia
  44. voice:+61 7 3407 4541            Death to the Daleks!!!!
  45. fax:  +61 7 3407 4607
  46. email: AL012@svtstu.seqeb.gov.au
  47.  
  48.